using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AudioManage : MonoBehaviour
{
    public static AudioManage instance;

    public AudioClip buttonClip;
    public AudioClip victorClip;
    
    
    private AudioSource buttonSource;
    public  AudioSource victorSource;
    public AudioClip failCilp;

    public Slider valueNumber1;
    public Slider valueNumber2;

    public AudioSource backSource;
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(this);
        }
        else
        {
            Destroy(gameObject);
        }
    }

    private void Start()
    {
        gameObject.AddComponent<AudioSource>();
        buttonSource = GetComponent<AudioSource>();
        buttonSource.clip = buttonClip;
        
        buttonSource.playOnAwake = false;

        victorSource.clip = victorClip;

        valueNumber1.value = buttonSource.volume;
        valueNumber1.onValueChanged.AddListener(OnValueChanged);
        valueNumber2.onValueChanged.AddListener(OnBackChanged);
    }

    public void PlayButtonAudio()
    {
        buttonSource.PlayOneShot(buttonClip);
    }

    

    public void OnValueChanged(float volume)
    {
        buttonSource.volume = volume;
    }

    public void OnBackChanged(float volume)
    {
        backSource.volume = volume;
    }

    public void VictorAudio()
    {
        victorSource.PlayOneShot(victorClip);
    }

    public void FailAudio()
    {
        victorSource.PlayOneShot(failCilp);
    }
    
    
}
